@extends('layouts.home')
@section('title', '沃势管理后台')
@section('style')
    <link href="../plugins/multiselect/css/multi-select.css"  rel="stylesheet" type="text/css" />
    <link href="../plugins/select2/css/select2.min.css" rel="stylesheet" type="text/css" />
    <link href="../plugins/bootstrap-select/css/bootstrap-select.min.css" rel="stylesheet" />
    <link rel="stylesheet" type="text/css" href="css/colorbox.css" />
    <link href="../plugins/bootstrap-sweetalert/sweet-alert.css" rel="stylesheet" type="text/css">
@endsection
@section('content')
    <div class="row">
        <div id="con-close-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
            <div class="modal-dialog">
                <form id="user-create" action="{{ route('setting.user.store') }}">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                            <h4 class="modal-title">新增用户</h4>
                        </div>
                        <div class="modal-body">
                            <div class="row">
                                <div class="form-group">
                                    <label class="col-sm-3 control-label" for="checkbox">所属角色组</label>
                                    <div class="col-sm-6">
                                        @inject('rolePresenter','App\Presenters\RolePresenter')
                                        {!! $rolePresenter->rolesCheckbox() !!}
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="form-group">
                                        <label for="field-3" class="control-label">用户名  <font color="red">*</font></label>
                                        <input type="text"  data-toggle="tooltip" name="name" data-trigger="hover" class="form-control tooltips" data-original-title="不可重复" value="{{ old('name') }}">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="form-group">
                                        <label for="field-3" class="control-label">邮箱  <font color="red">*</font></label>
                                        <input type="text"  data-toggle="tooltip" name="email" data-trigger="hover" class="form-control tooltips" data-original-title="不可重复" value="{{ old('email') }}">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-12">
                                    <div class="form-group">
                                        <label for="field-3" class="control-label">密码  <font color="red">*</font></label>
                                        <input type="password"  data-toggle="tooltip" name="password" data-trigger="hover" class="form-control tooltips" data-original-title="请输入密码" >
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default waves-effect" data-dismiss="modal">关闭</button>
                            <button type="submit" class="btn btn-info waves-effect waves-light">保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </div><!-- /.modal -->
        <div class="col-sm-12">
            <div class="card-box">
                <div class="row">
                    <form action="{{route('setting.user.index')}}" method="get">
                        <div class="col-sm-1">
                            <select class="form-control select2" name="id">
                                <option value="">请选择用户</option>
                                @foreach($data as $u)
                                    <option value="{{ $u->id }}" @if($u->id == request('id'))) selected @endif>{{ $u->name }}</option>
                                @endforeach
                            </select>
                        </div>
                        <div class="col-sm-3"><span class="input-group-btn">
                                <button type="submit" class="btn btn-default waves-effect w-md m-b-1">查询</button>
                            </span>
                        </div>
                    </form>
                    <div align="right">
                        <a class="btn btn-default waves-effect" data-toggle="modal" data-target="#con-close-modal"><i class="glyphicon glyphicon-plus"></i></a>
                        <a class="btn btn-danger deleteall" data-toggle="tooltip"  data-original-title="禁用" data-href="{{ route('setting.role.destroy.all') }}"><i class="fa fa-times-circle"></i></a>
                    </div>
                </div>
            </div>
            <div class="card-box">
                <div class="table-rep-plugin">
                    <div class="table-responsive" data-pattern="priority-columns">
                        <table class="tablesaw table m-b-0" data-tablesaw-mode="swipe" data-tablesaw-mode-switch data-tablesaw-minimap>
                            <thead>
                            <tr>
                                <th>
                                    <div class="checkbox checkbox-primary checkbox-single" style="margin-top: 0!important; margin-bottom: 0!important;">
                                        <input type="checkbox" id="selectall">
                                        <label for="selectall"></label>
                                    </div>
                                </th>
                                <th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="persist">ID</th>
                                <th scope="col" data-tablesaw-sortable-col data-tablesaw-sortable-default-col data-tablesaw-priority="2">姓名</th>
                                <th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="2">账号</th>
                                <th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="1">状态</th>
                                <th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="4">最后登录时间</th>
                                <th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="2">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($users as $u)
                                <tr>
                                    <td>
                                        <div class="checkbox checkbox-primary checkbox-single" style="margin-top: 0!important; margin-bottom: 0!important;">
                                            <input type="checkbox" name="id" id="id-{{ $u->id }}"
                                                   value="{{ $u->id }}" class="selectall-item"/>
                                            <label for="id-{{ $u->id }}"></label>
                                        </div>
                                    </td>
                                    <td>{{ $u->id }}</td>
                                    <td>{{ $u->name }}</td>
                                    <td>{{ $u->email }}</td>
                                    <td>{{ $u->status }}</td>
                                    <td>{{ $u->updated_at }}</td>
                                    <td>
                                        <a class="btn btn-default btn-sm view" href="{{ route('setting.user.edit', ['id'=>$u->id]) }}"><i class="fa fa-pencil"></i> 修改</a>
                                        <a data-href="{{ route('setting.user.destroy', ['id' => $u->id]) }}" class="btn btn-danger btn-sm user-delete"><i class="fa fa-times-circle"></i> 禁用</a>
                                    </td>
                                </tr>
                            @endforeach

                            </tbody>
                        </table>
                        <div align="right">
                            {{ $users->links() }}
                        </div>
                    </div>

                </div>

            </div>
        </div>
    </div>
    <!-- end row -->
    @section('script')
        <script src="../plugins/select2/js/select2.min.js" type="text/javascript"></script>
        <script src="../plugins/bootstrap-select/js/bootstrap-select.min.js" type="text/javascript"></script>
        <script type="text/javascript" src="js/jquery.colorbox.js"></script>
        <script src="../plugins/bootstrap-sweetalert/sweet-alert.min.js"></script>
        <script src="{{ asset('js/ajax.js') }}"></script>
        <script>
            $('.select2').select2();
            $(".view").colorbox({width:"60%", height:"90%", iframe:true});
            $('#user-create').submit(function(){
                var self = $(this);
                $.post(self.attr("action"), self.serialize(), success, "json").fail(function (res) {
                    console.log(res);
                    layer.msg(res.responseJSON.join('<br>'));
                });
                return false;
                function success(res) {
                    if (res.ack) location.reload();
                    layer.msg(res.msg);
                }
            });
            $(".user-delete").click(function () {
                Rbac.ajax.delete({
                    confirmTitle: '确定禁用用户?',
                    href: $(this).data('href'),
                    successTitle: '用户禁用成功'
                });
            });
            $(".deleteall").click(function () {
                Rbac.ajax.deleteAll({
                    confirmTitle: '确定禁用选中的用户?',
                    href: $(this).data('href'),
                    successTitle: '用户禁用成功'
                });
            });
        </script>
    @endsection
@stop














